/**
 * 时间戳转日期
 * @param nS
 * @returns {string}
 */
function timeToDate(nS, isS = false, isM = true, isH = true) {
    nS = parseInt(nS);
    if (nS <= 0 || isNaN(nS))
    {
        return '';
    }
    var time = new Date(nS * 1000);
    var y = time.getFullYear();
    var m = time.getMonth()+1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    let res = y+'-'+add0(m)+'-'+add0(d);
    if (isH)
    {
        res += ' ' + add0(h);
    }
    if (isM)
    {
        res += ':' + add0(mm);
    }
    if (isS)
    {
        res += ':' + add0(s);
    }
    return res;
}

/**
 * 时间拼装加0
 * @param m
 * @returns {*}
 */
function add0(m){
    return m < 10 ? '0' + m : m;
}

// 删除操作
function comDel(ids, url, tips = '是否确认删除?') {
    layer.confirm(tips, {icon: 7, title:'删除确认'}, function(){
        $.post(url, {ids: ids}, function (res) {
            if (res.code == 0) {
                layer.msg('删除成功!',{time: 1000}, function(){
                    window.location.reload();
                })
            } else {
                layer.msg(res.msg,{time: 1000, icon: 1000}, function(){
                    window.location.reload();
                })
            }
        }, 'json');
    })
}

/**
 * 打开相册
 * @param cb 回调函数,可直接操作返回的数组
 */
function openAlbum(cb){
    layer.open({
        type: 2,
        content: '/admin/album/index',
        area: ['750px', '600px'],
        btn: ['确定','关闭'],
        btnclass: ['btn-danger'],
        yes: function(index, layero){
            let frameWindow = window[layero.find('iframe')[0]['name']];
            let data = frameWindow.getPicList();
            cb(data)
            layer.close(index);
        },
        cancel: function(){
            //右上角关闭回调
        }
    });
}